package view.Battery
{
	import flash.display.BitmapData;
	
	import starling.core.Starling;
	import starling.display.Image;
	import starling.display.MovieClip;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.textures.Texture;
	
	public class BatteryView extends Sprite
	{
		private var _batteryMc:MovieClip;
		public function BatteryView()
		{
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage(event:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);	
			drawBattery();
            //旋转的中心点
			this.pivotX = 22
			this.pivotY = 22;
            this.touchable = false;
            addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
		}
		
		private function drawBattery():void
		{
			_batteryMc = new MovieClip(Assets.getAtlas().getTextures("gun"), 20);//降低帧频20
			_batteryMc.stop();
			Starling.juggler.add(_batteryMc);
			addChild(_batteryMc);
		}
		
		public function gunBang():void{
			if(_batteryMc.isPlaying)
				return;
			_batteryMc.play();
		}
		
		public function stopFire():void{
			if(_batteryMc.isPlaying){
                //以避免不播放完就停止
				if(_batteryMc.currentFrame == 1)
					_batteryMc.stop();
			}
		}

        //new add 
        private function onRemovedFromStage(e:Event):void{
            removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
        }
	}
}
